I'll show a few things. Python, heroku, nose, etc. They're just examples of things that exist for most general purpose languages.
Research, collaboration, peer review and publishing are perfect processes because people don't make mistakes and always understand one another perfectly.
Research, collaboration, peer review and publishing are perfect processes because people don't make mistakes and always understand one another perfectly.
Right...
So, let's take a look at a few things we could do better.
The only citation in this whole presentation!
How do you verify correctness?
Code that tests other code. It has the same advantages code does:
Until a friend and mentor of mine sat with me and helped me write my first tests, testing was black magic to me.
The difference it's made in my productivity & quality is too big to understate.
# fib.py
def fib(n):
# recursively calculate Fibonaacci numbers
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
How do we know it's right? I mean, it looks right... Right?
# tests.py
from fib import fib
def test_fib_output():
# Check some known values
assert fib(0) == 0
assert fib(1) == 1
assert fib(2) == 1
assert fib(3) == 2
assert fib(4) == 3
assert fib(5) == 5
(nosetests is just a program that automatically finds and runs your tests)
$ nosetests
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
Success!
On with our lives! We can change the code, our colleagues can change it, we can build on top of it, etc.
Alas, we soon find that this algorithm only gets us so far.
>>> fib(1000)
...
RuntimeError: maximum recursion depth exceeded
Well, crap.
We could just go and fix this.
But we can do one better! Let's write a new test to cover this case:
def test_fibr_large_numbers():
assert fibr(1000) > 0 # who even knows the 1000th Fibonacci number?!
and run it...
.E
----------------------------------------------------------------------
Ran 2 tests in 0.015s
FAILED (errors=1)
Failed - Back to work!
Let's replace our recursive fib() function with an iterative one!
Normally, we'd have to be really careful and make sure the new one just right. But instead, we have tests now to make sure we don't break anything.
Iterative version!
# fib.py
def fib(n):
# iterative Fibonaacci calculation
a, b = 0, 1
for i in range(0, n):
a, b = b, a + b
return a
Now run our exact same existing tests...
..
----------------------------------------------------------------------
Ran 2 tests in 0.015s
OK
Hooray!
Including collaboration with future you!
How do you collaborate with your colleagues? Email? Dropbox? Something better? Something worse?
Who here routinely runs software written by other researchers? Who improves on it?
The way that coders collaborate in the modern world.
Have you ever:
...you do use Stack Overflow, right?
(courtesy of the illustrious SO user si618, content CC BY-SA)
Think of it like email.
Github : Git :: Gmail : Email
(or, how to keep your sanity working in teams!)
We start by creating a git repository and hosting it somewhere everyone can get to it. Think of it like a dropbox folder with super powers tailor made for coding.
All the cool kids these days are using github, so we will too!
Creating a repository is actually pretty easy, and GitHub's documentation is particularly good:
https://help.github.com/
(see "Good Resources for Learing Git and Github")
Remember, it's like email -- you can use git via a GUI
(at least for some functionality)
Now what?
But, if you program every week and especially if you program with other people it is SO worth learning.
And it works with all sorts of great tools
It matters.
We can go through the motions, but we can also do better.
And, we can do better in two ways.
Administering and maintaining the whole thing is expensive and time consuming.
There is a better way!
I can't stress enough how many ways there are to make software available on the Internet.
I'll talk about just one, my favorite, but there are many, many good ones out there.
It turns out that this makes life easier even if you don't use heroku, etc.
yourthing.herokuapp.comyourthing.herokuapp.com/some/path/to/thing/10If only there was a good way to express exactly what that looked like compared to our existing code...
If only there was a good way to express exactly what that looked like compared to our existing code...
So, starting from our original fibonacci code, we've got
John Hess
john@jthess.com
| Table of contents | t |
|---|---|
| Exposé | ESC |
| Autoscale | e |
| Full screen slides | f |
| Presenter view | p |
| Source files | s |
| Slide numbers | n |
| Blank screen | b |
| Notes | 2 |
| Help | h |